package com.example.prison.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.prison.entity.AttendanceList;
import com.example.prison.entity.vo.AttendanceListVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【attendance_list】的数据库操作Mapper
* @createDate 2023-04-11 17:09:50
* @Entity com.example.military.entity.AttendanceList
*/
@Mapper
public interface AttendanceListMapper extends BaseMapper<AttendanceList> {

    @Select("select * from attendance_list order by record_id desc")
    List<AttendanceList> getAttendanceList();

//    @Select("select * from attendance_list a, attendance_device_info d where a.sn=d.device_number order by record_id desc")
    @Select("<script>select * from attendance_list a, attendance_device_info d" +
            " <where> a.sn=d.device_number " +
            " <if test=\"beginTime != null and beginTime != ''\">and a.time &gt;= #{beginTime} </if> " +
            " <if test=\"endTime != null and endTime != ''\">and a.time &lt;= #{endTime} </if> " +
            " </where> " +
            "order by record_id desc</script>")
    List<AttendanceListVO> getInfoList(@Param("beginTime") String beginTime, @Param("endTime")String endTime);

    @Insert("insert into attendance_list(id,time,sn,access,ptype)" +
            "values (#{id},#{time},#{sn},#{access},#{ptype})")
    void addAttendanceRecord(AttendanceList attendanceList);

    @Delete("<script>delete from attendance_list where record_id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteAttendanceList(@Param("ids") Integer[] ids);

    @Select("select * from attendance_list a, attendance_device_info d where a.time between #{beginTime} and #{endTime} and a.sn=d.device_number order by record_id desc")
    List<AttendanceListVO> getListByTime(@Param("beginTime")String beginTime, @Param("endTime")String endTime);

    @Select("select * from attendance_list where record_id=#{id} ")
    AttendanceList getById(@Param("id") Integer id);

    @Select("select * from attendance_list where sn=#{SN} order by record_id desc")
    List<AttendanceList> getBySN(@Param("SN") String SN);

    @Select("select * from attendance_list where time between #{beginTime} and #{endTime} and sn=#{SN} order by time desc LIMIT 4")
    List<AttendanceList> getBySNOrderByTime(@Param("SN") String SN, @Param("beginTime")String beginTime, @Param("endTime")String endTime);

    @Select("select * from attendance_list where time between #{beginTime} and #{endTime} and sn=#{SN} and ptype=#{ptype} order by time desc LIMIT 1")
    AttendanceList getBySNAndTimeAndPType(@Param("SN") String SN, @Param("beginTime")String beginTime, @Param("endTime")String endTime, @Param("ptype")String ptype);

}




